#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
using namespace std;

vector<vector<char> > a;
set<pair<int, int> > nex;
bool isw;

bool In(int x, int y){
    return 1<=x && x<=8 && 1<=y && y<=8;
}

const int DX[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int DY[] = {0, 0, -1, 1, -1, 1, 1, -1};
void scan(){
    nex.clear();
    char rev = isw? 'B':'W', now = isw? 'W':'B';
    for (int i = 1; i <= 8; ++i) {
        for (int j = 1; j <= 8; ++j) {
            if(a[i][j] != '-') continue;
            for (int k = 0; k < 8; ++k) {
                int x = i, y = j;
                int dx = DX[k], dy = DY[k];
                while(In(x+dx, y+dy) && a[x+dx][y+dy]==rev){x+=dx; y+=dy;}
                if(a[x][y] == rev && In(x+dx, y+dy) && a[x+dx][y+dy]==now){
                    nex.insert(make_pair(i, j));
                }
            }
        }
    }
}

void move(int x, int y){
    const int xx = x, yy = y;
    char now = (isw)? 'W':'B', rev = isw? 'B':'W';
    a[x][y] = now;
    
    for (int i=0; i<8; i++) {
        x = xx, y = yy;
        int dx = DX[i], dy = DY[i];
        while(In(x+dx, y+dy) && a[x+dx][y+dy]==rev){x+=dx; y+=dy;}
        if(a[x][y] == rev && In(x+dx, y+dy) && a[x+dx][y+dy]==now){
            int tx = xx, ty = yy;
            while(tx!=x || ty!=y){
                tx+=dx, ty+=dy;
                a[tx][ty] = now;
            }
        }
    }
    isw = !isw;
}
int main() {
//    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    int t=0;
    while(++t<=T){
        if(t>1) cout << "\n";
        a.assign(9, vector<char>(9, '-'));
        for (int i = 1; i <= 8; ++i) {
            for (int j = 1; j <= 8; ++j) {
                cin >> a[i][j];
            }
        }
        char ch; cin >> ch; isw = ch == 'W';

        while(cin >> ch){
            if(ch == 'L'){
                scan();
                if(nex.empty()) cout << "No legal move.\n";
                else{
                    for (auto i = nex.begin();  i!= nex.end(); i++) {
                        if(i != nex.begin())  cout << " ";
                        cout << "(" << i->first << "," << i->second << ")";
                    }
                    cout << "\n";
                }
            }
            else if(ch == 'M'){
                scan();
                if(nex.empty()) isw = !isw;
                int x = getchar()-'0', y = getchar() - '0';
                move(x, y);
                int cntw = 0, cntb = 0;
                for(int i=1; i<=8; ++i){
                    for(int j=1; j<=8; ++j){
                        if(a[i][j] == 'W') ++cntw;
                        else if (a[i][j] == 'B') ++cntb;
                    }
                }
                cout << "Black -" << setw(3) <<  cntb << " White -" << setw(3) << cntw << "\n";
            }
            else if(ch == 'Q') {
                for (int i = 1; i <= 8; ++i) {
                    for (int j = 1; j <= 8; ++j) {
                        cout << a[i][j];
                    }
                    cout << "\n";
                }
                break;
            }
        }
    }
    return 0;
}